Skip to content

fix: quadlet generator emits diagnostics to stderr under systemd-analyze verify#29079

Merged
giuseppe merged 2 commits into
podman-container-tools:mainfrom
mvanhorn:fix-quadlet-verify-stderr-logging
Jul 16, 2026
Merged

fix: quadlet generator emits diagnostics to stderr under systemd-analyze verify#29079
giuseppe merged 2 commits into
podman-container-tools:mainfrom
mvanhorn:fix-quadlet-verify-stderr-logging

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Running sudo systemd-analyze --generators verify <unit> against a broken quadlet printed no generator diagnostics, even though the same command without sudo (and podman-system-generator -dryrun) did. The cause is in cmd/quadlet/main.go: Logf wrote each line to /dev/kmsg and only fell back to stderr when that write failed or -dryrun was set. As root the kmsg write succeeds, so nothing was written to stderr, and systemd-analyze verify captures stderr rather than kmsg.

Logf now writes to /dev/kmsg best-effort (preserving the early-boot and journal logging that root services rely on at daemon-reload) and additionally always copies the same quadlet-generator[pid]: ... line to stderr, so systemd-analyze verify and interactive sudo runs surface the diagnostics. Rootless behavior, where kmsg is unavailable, is unchanged.

Checklist

Ensure you have completed the following checklist for your pull request to be reviewed:

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all commits. (git commit -s).
  • Referenced issues using Fixes: #00000 in commit message (if applicable)
  • Tests have been added/updated (or no tests are needed)
  • Documentation has been updated (or no documentation changes are needed)
  • All commits pass make validatepr (format/lint checks)
  • Release note entered in the section below (or None if no user-facing changes)

Does this PR introduce a user-facing change?

The quadlet generator now writes its diagnostics to stderr in addition to /dev/kmsg, so errors are visible under `systemd-analyze --generators verify` and other tooling that captures the generator's stderr, including when run as root.

Fixes #28888

Logf wrote to /dev/kmsg and only fell back to stderr when the kmsg
write failed or -dryrun was set. As root the kmsg write succeeds, so
nothing reached stderr and `sudo systemd-analyze --generators verify`
(which captures stderr, not kmsg) showed no diagnostics, while the same
command without sudo did.

Write to /dev/kmsg best-effort for early-boot/journal capture AND always
copy the same line to stderr so verify and interactive sudo runs surface
the messages. Rootless behavior is unchanged.

Fixes: podman-container-tools#28888
Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>

@Honny1 Honny1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Just one style question.

Comment thread cmd/quadlet/main.go Outdated
fmt.Fprintf(os.Stderr, "%s\n", line)
os.Stderr.Sync()
}
logToKmsg(line)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function returns a bool value; should it be like this?:

Suggested change
logToKmsg(line)
_ :=logToKmsg(line)

@Honny1

Honny1 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@mvanhorn Any updates on this?

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks @Honny1, and sorry for the delay. Good call — since Logf now always writes to stderr, logToKmsg's return is intentionally ignored (kmsg is best-effort), so I've made the discard explicit as _ = logToKmsg(line) in 6e20b31. (Minor: _ := ... won't compile — := needs a new variable, so it's _ =.)

@Honny1 Honny1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM once DCO is satisfied. (Just do git commit -s --amend)

Logf now always writes to stderr, so the kmsg write is best-effort and
its bool return is intentionally ignored. Make the discard explicit with
`_ = logToKmsg(line)` per review, rather than leaving it implicit.

Signed-off-by: mvanhorn <mvanhorn@gmail.com>
@mvanhorn mvanhorn force-pushed the fix-quadlet-verify-stderr-logging branch from 6e20b31 to 6d57281 Compare July 16, 2026 03:04
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Signed off the second commit (the first was already signed), DCO is green now. Thanks for the review!

@packit-as-a-service

Copy link
Copy Markdown

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

@Honny1 Honny1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

PTAL @podman-container-tools/podman-reviewers @podman-container-tools/podman-maintainers

@jankaluza

Copy link
Copy Markdown
Contributor

LGTM. Test failure looks like temporary issue.

@Honny1

Honny1 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Yes, Packit is unstable.

@giuseppe giuseppe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@giuseppe

Copy link
Copy Markdown
Contributor

failure is unrelated

@giuseppe giuseppe merged commit 72da6a0 into podman-container-tools:main Jul 16, 2026
69 of 70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No systemd-analyze output using sudo

4 participants